package com.controller;

import com.domain.VideoComment;
import com.dto.JsonResponse;
import com.dto.PageResult;
import com.service.impl.VideoCommentServiceImpl;
import com.support.UserSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/videoComment")
@RestController
public class VideoCommentApi {

    @Autowired
    private VideoCommentServiceImpl videoService;

    @Autowired
    private UserSupport userSupport;

    @GetMapping("/getVideoComment")
    public JsonResponse<VideoComment> getVideoComment(@RequestParam Long videoId) {
        VideoComment result = videoService.getVideoComment(videoId);
        return new JsonResponse<>(result);
    }

    /**
     * 分页查询视频评论
     */
    @GetMapping("/pageListVideoComment")
    public JsonResponse<PageResult<VideoComment>> pageListVideoComment(@RequestParam("size") Integer size,
                                                                       @RequestParam("no") Integer no,
                                                                       @RequestParam("videoId") Long videoId) {
        PageResult<VideoComment> result = videoService.pageListVideoComments(size, no, videoId);
        return new JsonResponse<>(result);
    }

    /**
     * 添加视频评论
     */
    @PostMapping("/addVideoComment")
    public JsonResponse<String> addVideoComment(@RequestBody VideoComment videoComment) {
        Long userId = userSupport.getCurrentUserId();
        videoService.addVideoComment(videoComment, userId);
        return JsonResponse.success();
    }

}

